/*
 ********************************************************************************
 * Copyright (c) 2012 Samsung Electronics, Inc.
 * All rights reserved.
 *
 * This software is a confidential and proprietary information of Samsung
 * Electronics, Inc. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with Samsung Electronics.
 ********************************************************************************
 */

package com.ubisolv.vmakeup.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Adapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.ubisolv.vmakeup.R;
import com.ubisolv.vmakeup.data.StyleColorData;

/**
 * A {@link BaseAdapter} implementation that provides a list of applications.
 *
 * @author sprc
 *
 */
public class StyleMenuAdapter extends BaseAdapter {

	private final Context mContext;
	private final LayoutInflater mInflater;
	//private List<Integer> mData;
	private int[] mStyle =	null;
	private int mMakeupId =	-1;
	private OnClickListener mOnClickListener =	null;

	public StyleMenuAdapter(final Context ctx) {
		super();
		
		mContext = 	ctx;
		mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	public StyleMenuAdapter(final Context ctx, OnClickListener listener) {
		super();
		
		mContext = 	ctx;
		mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		mOnClickListener =	listener;	
	}
	
	public StyleMenuAdapter(final Context ctx, int makeupId) {
		super();
		
		mContext = 	ctx;
		mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		//mData = new ArrayList<Integer>();
		mMakeupId =	makeupId;
		mStyle =	StyleColorData.getStyle(mMakeupId);
	}
	
	public void setMakeupId(int makeupId) {
		mMakeupId =	makeupId;
		mStyle =	StyleColorData.getStyle(mMakeupId);
		
		notifyDataSetChanged();
	}
	
	/**
	 * Since we want to loop our list we return {@link Integer#MAX_VALUE}.
	 *
	 * {@inheritDoc}
	 */
	public int getCount() {
    	int result =	0;
    	
    	if (mStyle != null) {
    		result =	mStyle.length;
    	}
    	
        return result;
	}

	/**
	 * Retrieves an item in a position from the range (0; {@link Integer#MAX_VALUE}).
	 *
	 * {@inheritDoc}
	 */
	public Object getItem(final int position) {
    	int result =	-1;
    	
    	if (mStyle != null && position < mStyle.length) {
    		result =	mStyle[position];
    	}
    	
    	return result;
	}

	public long getItemId(final int position) {
		return position;
	}

	public View getView(final int position, final View convertView, final ViewGroup parent) {
		View v =			mInflater.inflate(R.layout.listitem_style_layout, null);
        ImageView image =	(ImageView)v.findViewById(R.id.item);
        image.setImageResource(mStyle[position]);
        
        v.setTag(R.id.key_list_type, R.id.lst_style);
        v.setTag(R.id.key_list_value, mStyle[position]);
        v.setOnClickListener(mOnClickListener);
        
		return v;
	}

}
